package org.dreamwork.jasmine2.parser;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2009-1-22
 * Time: 15:54:24
 */
public class IncludeDirective extends JspDirective{
    private String file;
    protected IncludeDirective (String content) {
        super (content);
        type = JspDirective.TYPE_INCLUDE;
    }

    public void parse () throws ParseException {
        if (content.indexOf ("file") == -1)
            throw new ParseException ("include directive must have file attribute");
        String[] a = content.split ("=");
        if (a.length != 2)
            throw new ParseException ("include directive must be well format!");
        file = a[1].trim ();
        char first = file.charAt (0);
        if (first != '\'' && first != '"')
            throw new ParseException ("include directive must be well format!");
        char last = file.charAt (file.length () - 1);
        if (first != last)
            throw new ParseException ("include directive must be well format!");
        file = new String (file.toCharArray (), 1, file.length () - 2);
    }

    public String toString () {
        return "<%@include file=\"" + file + "\"%>";
    }
}
